/*
FileName    :core.js
Author      :胡尐睿丶
Website     :http://www.cnblogs.com/hooray/archive/2012/02/29/2372952.html
Version     :20120520
*/

var version = '20120520';
var ajaxUrl = 'Ajax/Index.ashx';  //所有ajax操作指向页面
var zoomlevel = 1;
var TEMP = HROS = {};

HROS.CONFIG = {
	desk: 1,                //当前显示桌面
	dockPos :'top',         //应用码头位置，参数有：top,left,right
	appXY :'x',             //图标排列方式，参数有：x,y
	shortcutTop :20,        //快捷方式top初始位置
	shortcutLeft :20,       //快捷方式left初始位置
	createIndexid :1,       //z-index初始值
	windowMinWidth :215,    //窗口最小宽度
	windowMinHeight :59,    //窗口最小高度
	wallpaper :'',          //壁纸
	wallpaperWidth :0,      //壁纸宽度
	wallpaperHeight :0,     //壁纸高度
	wallpaperType :''       //壁纸显示方式，参数有：tianchong,shiying,pingpu,lashen,juzhong
};

/*
**  一个不属于其他模块的模块
*/
HROS.base = (function(){
	return {
		/*
		**	系统初始化
		*/
		init: function(){
			//绑定body点击事件，主要目的就是为了强制隐藏右键菜单
			$('body').on('click',function(){
				$('.popup-menu').hide();
			});
			//绑定浏览器resize事件
			HROS.base.resize();
			//用于判断网页是否缩放，该功能提取自QQ空间
			HROS.zoom.init();
			//加载壁纸
			HROS.wallpaper.get();
			//初始化分页栏
			HROS.navbar.init();
			//绑定任务栏点击事件
			HROS.taskbar.init();
			//获得dock的位置
			HROS.dock.getPos(function(){
				//获取图标排列顺序
				HROS.app.getXY(function(){
					/*
					**      当dockPos为top时          当dockPos为left时         当dockPos为right时
					**  -----------------------   -----------------------   -----------------------
					**  | o o o         dock  |   | o | o               |   | o               | o |
					**  -----------------------   | o | o               |   | o               | o |
					**  | o o                 |   | o | o               |   | o               | o |
					**  | o +                 |   |   | o               |   | o               |   |
					**  | o             desk  |   |   | o         desk  |   | o         desk  |   |
					**  | o                   |   |   | +               |   | +               |   |
					**  -----------------------   -----------------------   -----------------------
					**  因为desk区域的尺寸和定位受dock位置的影响，所以加载图标前必须先定位好dock的位置
					*/
					HROS.app.get();
				});
			});
			//绑定应用码头2个按钮的点击事件
			$('.dock-tool-pinyin').on('mousedown',function(){
				return false;
			}).on('click',function(){
				javascript:(function(q){q?q.toggle():function(d,j){j=d.createElement('script');j.async=true;j.src='//ime.qq.com/fcgi-bin/getjs';j.setAttribute('ime-cfg','lt=2');d=d.getElementsByTagName('head')[0];d.insertBefore(j,d.firstChild)}(document)})(window.QQWebIME);
			});
			$('.dock-tool-style').on('mousedown',function(){
				return false;
			}).on('click',function(){
				HROS.window.create(0,{num:"ztsz",title:"主题设置",url:"themes.aspx",width:580,height:520,resize:false});
			});
			//桌面右键
			$('#desk').on('contextmenu',function(e){
				$(".popup-menu").hide();
				var popupmenu = HROS.popupMenu.desk();
				l = ($(document).width()-e.clientX)<popupmenu.width() ? (e.clientX-popupmenu.width()) : e.clientX;
				t = ($(document).height()-e.clientY)<popupmenu.height() ? (e.clientY-popupmenu.height()) : e.clientY;
				popupmenu.css({left:l+'px',top:t+'px'}).show();
				return false;
			});
		},
		logout: function(){
			$.ajax({
				type: 'POST',
				url: ajaxUrl,
				data: 'ac=logout',
				success: function(){
					$('.loginmask').fadeIn('fast',function(){
						//清空桌面图标
						$('#desk ul').html('');
						//清空桌面窗口
						$('#desk .window-container').remove();
						//清空任务栏
						$('#task-content-inner').html('');
						//清空应用码头
						$('#dock-container .dock-applist').html('');
						//重置分页导航
						$('#navContainer').removeClass('nav-current-1 nav-current-2 nav-current-3 nav-current-4 nav-current-5').addClass('nav-current-1');
						$('.desktop').hide();
						$('.login').show();
						$(this).hide();
					});
				}
			});
		},
		resize: function(){
			$(window).on('resize',function(){
				HROS.deskTop.resize(250);
				HROS.wallpaper.set();
			});
		},
		help: function(){
			if($.browser.msie && $.browser.version!=="9.0"){
				//IE6,7,8基本就告别新手帮助了
			}else{
				$('#help').show();
				$('#step1').show();
				$('.close').on('click',function(){
					$('.step').hide();
					$('#help').hide();
				});
				$('.next').on('click',function(){
					var obj = $(this).parents('.step');
					var step = obj.attr('step');
					obj.hide();
					$('#step'+(parseInt(step)+1)).show();
				});
				$('.over').on('click',function(){
					$(this).parents('.step').hide();
					$('#help').hide();
				});
			}
		}
	}
})();

/*
**  一个从QQ空间提取出来的插件
**  用于判断页面是否进行了缩放操作，并给予提示
**  可在浏览页时按住ctrl+鼠标滚轮进行测试预览
*/
HROS.zoom = (function(){
	return {
		/*
		**  初始化
		**  其实也不用初始化，可以直接把object代码写在页面上
		**  需要注意的是onchange参数，调用的是HROS.zoom.check方法
		*/
		init: function(){
			$('body').append('<object data="js/zoom.swf?onchange=HROS.zoom.check" width="10" height="10" id="accessory_zoom" name="zoom_detect" type="application/x-shockwave-flash"><param name="allowScriptAccess" value="always"><param name="wmode" value="transparent"><param name="scale" value="noScale"></object>');
		},
		/*
		**  为什么会有个参数o？其实我也不知道
		**  我只知道o.scale的值是数字，当o.scale大于1时，页面处于放大状态，反之则为缩小状态
		*/
		check: function(o){
			var s = o.scale, m = s > 1 ? '放大' : '缩小';
			if(s != 1){
				zoomlevel = s;
				$('#zoom-tip').show().find('span').text("您的浏览器目前处于" + m + "状态，会导致显示不正常，您可以键盘按“ctrl+数字0”组合键恢复初始状态！");
			}else{
				if(s != zoomlevel){
					$('#zoom-tip').fadeOut();
				}
			}
		},
		/*
		**  关闭，其实是删除，如果想做关闭，把代码改成hide()即可
		*/
		close: function(){
			$('#zoom-tip').remove();
		}
	}
})();

/*
**  图标布局格子
**  这篇文章里有简单说明格子的作用
**  http://www.cnblogs.com/hooray/archive/2012/03/23/2414410.html
*/
HROS.grid = (function(){
	return {
		getAppGrid: function(){
			//可视宽高，列行，可放置图标数
			var width, height, col, row, sum;
			width = $('#desk-'+HROS.CONFIG.desk).width() - HROS.CONFIG.shortcutLeft;
			height = $('#desk-'+HROS.CONFIG.desk).height() - HROS.CONFIG.shortcutTop;
			col = parseInt(width / 120);
			row = parseInt(height / 100);
			sum = 10000;
			//开始绘制表格
			var appGrid = [], i = 0, _top = HROS.CONFIG.shortcutTop, _left = HROS.CONFIG.shortcutLeft;
			for(; i < sum; i++){
				appGrid.push({
					startY: _top,
					endY: _top + 100,
					startX: _left,
					endX: _left + 120
				});
				if(HROS.CONFIG.appXY == 'x'){
					_left += 120;
					if(_left + 100 > width){
						_top += 100;
						_left = HROS.CONFIG.shortcutLeft;
					}
				}else{
					_top += 100;
					if(_top + 70 > height){
						_top = HROS.CONFIG.shortcutTop;
						_left += 120;
					}
				}
			}
			return appGrid;
		},
		searchAppGrid: function(x, y){
			var grid = HROS.grid.getAppGrid(), i = 0, j = grid.length;
			var flags = 0, appLength = $('#desk-'+HROS.CONFIG.desk+' li.shortcut').length - 1, curr;
			for(; i < j; i++){
				curr = grid[i];
				if(x >= curr.startX && x <= curr.endX){
					flags += 1;
				}
				if(y >= curr.startY && y <= curr.endY){
					flags += 1;
				}
				if(flags === 2){
					return i > appLength ? appLength : i;
				}else{
					flags = 0;
				}
			}
			return null;
		},
		getDockAppGrid: function(){
			var dock = $("#dock-bar .dock-applist");
			//可视宽高
			var width = dock.width(), height = dock.height();
			var dockAppGrid = [], i = 0, _left = 0, _top = 0;
			for(; i < 7; i++){
				dockAppGrid.push({
					startY: _top,
					endY: _top + 62,
					startX: _left,
					endX: _left + 62
				});
				_top += 62;
				if(_top + 62 > height){
					_top = 0;
					_left += 62;
				}
			}
			return dockAppGrid;
		},
		searchDockAppGrid: function(x, y){
			var grid = HROS.grid.getDockAppGrid(), i = 0, j = grid.length, flags = 0, curr,
				appLength = $("#dock-bar .dock-applist li.shortcut").length - 1;
			for(; i < j; i++){
				curr = grid[i];
				if(x >= curr.startX && x <= curr.endX){
					flags += 1;
				}
				if(y >= curr.startY && y <= curr.endY){
					flags += 1;
				}
				if(flags === 2){
					return i > appLength ? appLength : i;
				}else{
					flags = 0;
				}
			}
			return null;
		},
		getFolderGrid: function(){
			var folderGrid = [];
			$('.folder-window:visible').each(function(){
				folderGrid.push({
					zIndex: $(this).css('z-index'),
					id: $(this).attr('window'),
					startY: $(this).offset().top,
					endY: $(this).offset().top + $(this).height(),
					startX:  $(this).offset().left,
					endX:  $(this).offset().left +  $(this).width()
				});
			});
			folderGrid.sort(function(x, y){
				return y['zIndex'] - x['zIndex'];
			});
			return folderGrid;
		},
		searchFolderGrid: function(x, y){
			var folderGrid = HROS.grid.getFolderGrid(), i = 0, j = folderGrid.length, flags = 0, curr;
			for(; i < j; i++){
				curr = folderGrid[i];
				if(x >= curr.startX && x <= curr.endX){
					flags += 1;
				}
				if(y >= curr.startY && y <= curr.endY){
					flags += 1;
				}
				if(flags === 2){
					return folderGrid[i]['id'];
				}else{
					flags = 0;
				}
			}
			return null;
		}
	}
})();

/*
**  桌面
*/
HROS.deskTop = (function(){
	return {
		/*
		**  处理浏览器改变大小后的事件
		*/
		resize: function(time){
			//使用doTimeout插件，防止出现resize两次的bug
			$.doTimeout('resize', time, function(){
				HROS.dock.getPos(fun);
				function fun(){
					HROS.taskbar.resize();
					//更新图标定位
					HROS.deskTop.appresize();
					//更新窗口定位
					HROS.deskTop.windowresize();
					//更新滚动条
					HROS.app.getScrollbar();
				}
			});
		},
		/*
		**  重新排列图标
		*/
		appresize: function(){
			var grid = HROS.grid.getAppGrid(), dockGrid = HROS.grid.getDockAppGrid();
			$("#dock-bar .dock-applist li").each(function(i){
				$(this).animate({"left":dockGrid[i]['startX'],"top":dockGrid[i]['startY']},500);
			});
			for(var j=1; j<=5; j++){
				$('#desk-'+j+' li').each(function(i){
					$(this).animate({"left":grid[i]['startX']+16,"top":grid[i]['startY']+7},500);
				});
			}
		},
		/*
		**  重新定位窗口位置
		*/
		windowresize: function(){
			$("#desk div.window-container").each(function(){
				var windowdata = $(this).data('info');
				currentW = $(window).width() - $(this).width();
				currentH = $(window).height() - $(this).height();
				_l = windowdata['left']/windowdata['emptyW']*currentW >= currentW ? currentW : windowdata['left']/windowdata['emptyW']*currentW;
				_l = _l <= 0 ? 0 : _l;
				_t = windowdata['top']/windowdata['emptyH']*currentH >= currentH ? currentH : windowdata['top']/windowdata['emptyH']*currentH;
				_t = _t <= 0 ? 0 : _t;
				$(this).animate({"left":_l+"px","top":_t+"px"},500);
			});
		}
	}
})();

/*
**  图标
*/
HROS.app = (function(){
	return {
		/*
		**  获得图标排列方式，x横向排列，y纵向排列
		*/
		getXY: function(fun){
			$.ajax({
				type: 'POST',
				url: ajaxUrl,
				data: 'ac=getAppXY',
				success: function(i){
					HROS.CONFIG.appXY = i;
					if(typeof(fun) != 'undefined'){
						fun();
					}
				}
			});
		},
		/*
		**  更新图标排列方式
		*/
		updateXY: function(i,fun){
			$.ajax({
				type: 'POST',
				url: ajaxUrl,
				data: 'ac=setAppXY&appxy='+i,
				success: function(){
					HROS.CONFIG.appXY = i;
					if(typeof(fun) != 'undefined'){
						fun();
					}
				}
			});
		},
		/*
		**  获取图标
		*/
		get: function(){
			//绘制图标表格
			var grid = HROS.grid.getAppGrid(), dockGrid = HROS.grid.getDockAppGrid(), i = 0;
			//获取json数组并循环输出每个图标
			$.getJSON(ajaxUrl+"?ac=getMyApp",function(sc){
				//加载应用码头图标
//				if(sc['startY'] != null){
                
					var dock_append = '';
					for(i=0; i<sc['dockapp'].length; i++){
//						if(sc['dockapp'][i]['apptype'] == 'app'){
							TEMP.dockAppTemp = {"top":dockGrid[i]['startY'],"left":dockGrid[i]['startX'],"title":sc['dockapp'][i]['name'],"shortcut":sc['dockapp'][i]['id'],"imgsrc":sc['dockapp'][i]['icon']};
							
                            dock_append += String.formatmodel(appTemp,TEMP.dockAppTemp);
                            alert(dock_append);
//						}else if(sc['dockapp'][i]['apptype'] == 'folder'){
//							TEMP.dockFolderTemp = {"top":dockGrid[i]['startY'],"left":dockGrid[i]['startX'],"title":sc['dockapp'][i]['iconName'],"shortcut":sc['dockapp'][i]['id'],"imgsrc":sc['dockapp'][i]['iconUrl']};
//							dock_append += String.formatmodel(folderTemp,TEMP.dockFolderTemp);
//						}
					}
					$("#dock-bar .dock-applist").html('').append(dock_append);
//				}
				i = 0;
				//加载桌面图标
				for(var j=1; j<=5; j++){
					var ul_append = '';
					if(sc['desk'+j+'app'] != null){
						for(; i<sc['desk'+j+'app'].length; i++){
							if(sc['desk'+j+'app'][i]['apptype'] == 'app'){
								TEMP.appTemp = {"top":grid[i]['startY']+7,"left":grid[i]['startX']+16,"title":sc['desk'+j+'app'][i]['iconName'],"shortcut":sc['desk'+j+'app'][i]['id'],"imgsrc":sc['desk'+j+'app'][i]['iconUrl']};
								ul_append += String.formatmodel(appTemp,TEMP.appTemp);
							}else if(sc['desk'+j+'app'][i]['apptype'] == 'folder'){
								TEMP.folderTemp = {"top":grid[i]['startY']+7,"left":grid[i]['startX']+16,"title":sc['desk'+j+'app'][i]['iconName'],"shortcut":sc['desk'+j+'app'][i]['id'],"imgsrc":sc['desk'+j+'app'][i]['iconUrl']};
								ul_append += String.formatmodel(folderTemp,TEMP.folderTemp);
							}
						}
					}
					ul_append += '<li class="add-app" style="left:'+(grid[i]['startX']+16)+'px;top:'+(grid[i]['startY']+7)+'px"><i class="shortcut-addicon"></i><span>添加应用</span></li>';
					$('#desk-'+j+' li').remove();
					$('#desk-'+j).append(ul_append);
					i = 0;
				}
				//绑定'应用市场'图标点击事件
				$('body').on('click','li.add-app',function(){
					HROS.window.create(0,{num:"yysc",title:"应用市场",url:"addapp.aspx",width:800,height:484,resize:false});
				});
				//绑定图标拖动事件
				HROS.app.move();
				//绑定应用码头拖动事件
				HROS.dock.move();
				//加载滚动条
				HROS.app.getScrollbar();
				//绑定滚动条拖动事件
				HROS.app.moveScrollbar();
				//绑定图标右击事件
				$('body').find('li.shortcut').on('contextmenu',function(e){
					$(".popup-menu").hide();
					if($(this).hasClass('app')){
						var popupmenu = HROS.popupMenu.app($(this));
						var l = ($(document).width()-e.clientX)<popupmenu.width() ? (e.clientX-popupmenu.width()) : e.clientX;
						var t = ($(document).height()-e.clientY)<popupmenu.height() ? (e.clientY-popupmenu.height()) : e.clientY;
						popupmenu.css({left:l+'px',top:t+'px'}).show();
					}else{
						var popupmenu = HROS.popupMenu.folder($(this));
						var l = ($(document).width()-e.clientX)<popupmenu.width() ? (e.clientX-popupmenu.width()) : e.clientX;
						var t = ($(document).height()-e.clientY)<popupmenu.height() ? (e.clientY-popupmenu.height()) : e.clientY;
						popupmenu.css({left:l+'px',top:t+'px'}).show();
					}
					return false;
				});
			});
		},
		/*
		**  图标拖动
		**  这块代码略多，主要处理了9种情况下的拖动，分别是：
		**  桌面拖动到应用码头、桌面拖动到文件夹内、当前桌面上拖动(排序)
		**  应用码头拖动到桌面、应用码头拖动到文件夹内、应用码头上拖动(排序)
		**  文件夹内拖动到桌面、文件夹内拖动到应用码头、不同文件夹之间拖动
		*/
		move: function(){
			//应用码头图标拖动
			$('#dock-bar .dock-applist').off('mousedown','li.app, li.folder').on('mousedown','li.app, li.folder',function(e){
				e.preventDefault();
				e.stopPropagation();
				if(e.button == 0 || e.button == 1){
					var oldobj = $(this), x, y, cx, cy, dx, dy, lay, obj = $('<li id="shortcut_shadow">'+oldobj.html()+'</li>');
					dx = cx = e.clientX;
					dy = cy = e.clientY;
					x = dx - oldobj.offset().left;
					y = dy - oldobj.offset().top;
					//绑定鼠标移动事件
					$(document).on("mousemove",function(e){
						$('body').append(obj);
						lay = HROS.maskBox.desk();
						lay.show();
						cx = e.clientX <= 0 ? 0 : e.clientX >= $(document).width() ? $(document).width() : e.clientX;
						cy = e.clientY <= 0 ? 0 : e.clientY >= $(document).height() ? $(document).height() : e.clientY;
						_l = cx - x;
						_t = cy - y;
						if(dx != cx || dy != cy){
							obj.css({left:_l, top:_t}).show();
						}
					});
					//绑定鼠标抬起事件
					$(document).on("mouseup",function(){
						$(document).off("mousemove").off("mouseup");
						obj.remove();
						if(typeof(lay) == 'object'){
							lay.hide();
						}
						//判断是否移动图标，如果没有则判断为click事件
						if(dx == cx && dy == cy){
							HROS.window.create(oldobj.attr('shortcut'));
							return false;
						}
						var folderId = HROS.grid.searchFolderGrid(cx, cy);
						if(folderId != null){
							if(oldobj.hasClass('folder') == false){
								$.ajax({
									type: "POST",
									url: ajaxUrl,
									data: "ac=updateMyApp&movetype=dock-folder&id="+oldobj.attr('shortcut')+"&from="+oldobj.index()+"&to="+folderId+"&desk="+HROS.CONFIG.desk,
									success: function(){
										oldobj.remove();
										HROS.deskTop.appresize();
										HROS.window.updateFolder(folderId);
									}
								});
							}
						}else{
							var icon, icon2;
							var iconIndex = $('#desk-'+HROS.CONFIG.desk+' li.shortcut').length == 0 ? -1 : $('#desk-'+HROS.CONFIG.desk+' li').index(oldobj);
							var iconIndex2 = $("#dock-bar .dock-applist").html() == '' ? -1 : $("#dock-bar .dock-applist li").index(oldobj);
							
							var dock_w2 = HROS.CONFIG.dockPos == 'left' ? 0 : HROS.CONFIG.dockPos == 'top' ? ($(window).width()-$("#dock-bar .dock-applist").width()-20)/2 : $(window).width()-$("#dock-bar .dock-applist").width();
							var dock_h2 = HROS.CONFIG.dockPos == 'top' ? 0 : ($(window).height()-$("#dock-bar .dock-applist").height()-20)/2;
							icon2 = HROS.grid.searchDockAppGrid(cx - dock_w2, cy - dock_h2);
							if(icon2 != null && icon2 != oldobj.index()){
								$.ajax({
									type: "POST",
									url: ajaxUrl,
									data: "ac=updateMyApp&movetype=dock-dock&id="+oldobj.attr('shortcut')+"&from="+oldobj.index()+"&to="+icon2+"&desk="+HROS.CONFIG.desk,
									success: function(){
										if(icon2 < iconIndex2){
											$("#dock-bar .dock-applist li.shortcut:eq("+icon2+")").before(oldobj);
										}else if(icon2 > iconIndex2){
											$("#dock-bar .dock-applist li.shortcut:eq("+icon2+")").after(oldobj);
										}
										HROS.deskTop.appresize();
									}
								});
							}else{
								var dock_w = HROS.CONFIG.dockPos == 'left' ? 73 : 0;
								var dock_h = HROS.CONFIG.dockPos == 'top' ? 73 : 0;
								icon = HROS.grid.searchAppGrid(cx - dock_w, cy - dock_h);
								if(icon != null){
									$.ajax({
										type: "POST",
										url: ajaxUrl,
										data: "ac=updateMyApp&movetype=dock-desk&id="+oldobj.attr('shortcut')+"&from="+oldobj.index()+"&to="+(icon+1)+"&desk="+HROS.CONFIG.desk,
										success: function(){
											if(icon < iconIndex){
												$("#desk-"+HROS.CONFIG.desk+" li.shortcut:eq("+icon+")").before(oldobj);
											}else if(icon > iconIndex){
												$("#desk-"+HROS.CONFIG.desk+" li.shortcut:eq("+icon+")").after(oldobj);
											}else{
												if(iconIndex == -1){
													$("#desk-"+HROS.CONFIG.desk+" li.add-app").before(oldobj);
												}
											}
											HROS.deskTop.appresize();
										}
									});
								}
							}
						}
						if($.browser.msie){
							lay[0].releaseCapture();
						}
					});
					if($.browser.msie){
						lay[0].setCapture();
					}
				}
				return false;
			});
			//桌面图标拖动
			$('#desk ul').off('mousedown','li.app, li.folder').on('mousedown','li.app, li.folder',function(e){
				e.preventDefault();
				e.stopPropagation();
				if(e.button == 0 || e.button == 1){
					var oldobj = $(this), x, y, cx, cy, dx, dy, lay, obj = $('<li id="shortcut_shadow">'+oldobj.html()+'</li>');
					dx = cx = e.clientX;
					dy = cy = e.clientY;
					x = dx - oldobj.offset().left;
					y = dy - oldobj.offset().top;
					//绑定鼠标移动事件
					$(document).on("mousemove",function(e){
						$('body').append(obj);
						lay = HROS.maskBox.desk();
						lay.show();
						cx = e.clientX <= 0 ? 0 : e.clientX >= $(document).width() ? $(document).width() : e.clientX;
						cy = e.clientY <= 0 ? 0 : e.clientY >= $(document).height() ? $(document).height() : e.clientY;
						_l = cx - x;
						_t = cy - y;
						if(dx != cx || dy != cy){
							obj.css({left:_l, top:_t}).show();
						}
					});
					//绑定鼠标抬起事件
					$(document).on("mouseup",function(){
						$(document).off("mousemove").off("mouseup");
						obj.remove();
						if(typeof(lay) == 'object'){
							lay.hide();
						}
						//判断是否移动图标，如果没有则判断为click事件
						if(dx == cx && dy == cy){
							HROS.window.create(oldobj.attr('shortcut'));
							return false;
						}
						var folderId = HROS.grid.searchFolderGrid(cx, cy);
						if(folderId != null){
							if(oldobj.hasClass('folder') == false){
								$.ajax({
									type: "POST",
									url: ajaxUrl,
									data: "ac=updateMyApp&movetype=desk-folder&id="+oldobj.attr('shortcut')+"&from="+oldobj.index()+"&to="+folderId+"&desk="+HROS.CONFIG.desk,
									success: function(){
										oldobj.remove();
										HROS.deskTop.appresize();
										HROS.window.updateFolder(folderId);
									}
								});
							}
						}else{
							var icon, icon2;
							var iconIndex = $('#desk-'+HROS.CONFIG.desk+' li.shortcut').length == 0 ? -1 : $('#desk-'+HROS.CONFIG.desk+' li').index(oldobj);
							var iconIndex2 = $("#dock-bar .dock-applist").html() == '' ? -1 : $("#dock-bar .dock-applist li").index(oldobj);
							
							var dock_w2 = HROS.CONFIG.dockPos == 'left' ? 0 : HROS.CONFIG.dockPos == 'top' ? ($(window).width()-$("#dock-bar .dock-applist").width()-20)/2 : $(window).width()-$("#dock-bar .dock-applist").width();
							var dock_h2 = HROS.CONFIG.dockPos == 'top' ? 0 : ($(window).height()-$("#dock-bar .dock-applist").height()-20)/2;
							icon2 = HROS.grid.searchDockAppGrid(cx - dock_w2, cy - dock_h2);
							if(icon2 != null){
								$.ajax({
									type: "POST",
									url: ajaxUrl,
									data: "ac=updateMyApp&movetype=desk-dock&id="+oldobj.attr('shortcut')+"&from="+oldobj.index()+"&to="+(icon2+1)+"&desk="+HROS.CONFIG.desk,
									success: function(){
										if(icon2 < iconIndex2){
											$("#dock-bar .dock-applist li.shortcut:eq("+icon2+")").before(oldobj);
										}else if(icon2 > iconIndex2){
											$("#dock-bar .dock-applist li.shortcut:eq("+icon2+")").after(oldobj);
										}else{
											if(iconIndex2 == -1){
												$("#dock-bar .dock-applist").append(oldobj);
											}
										}
										if($("#dock-bar .dock-applist li.shortcut").length > 7){
											$("#desk-"+HROS.CONFIG.desk+" li.shortcut").last().after($("#dock-bar .dock-applist li.shortcut").last());
										}
										HROS.deskTop.appresize();
									}
								});
							}else{
								var dock_w = HROS.CONFIG.dockPos == 'left' ? 73 : 0;
								var dock_h = HROS.CONFIG.dockPos == 'top' ? 73 : 0;
								icon = HROS.grid.searchAppGrid(cx - dock_w, cy - dock_h);
								if(icon != null && icon != oldobj.index()){
									$.ajax({
										type: "POST",
										url: ajaxUrl,
										data: "ac=updateMyApp&movetype=desk-desk&id="+oldobj.attr('shortcut')+"&from="+oldobj.index()+"&to="+icon+"&desk="+HROS.CONFIG.desk,
										success: function(){
											if(icon < iconIndex){
												$("#desk-"+HROS.CONFIG.desk+" li.shortcut:eq("+icon+")").before(oldobj);
											}else if(icon > iconIndex){
												$("#desk-"+HROS.CONFIG.desk+" li.shortcut:eq("+icon+")").after(oldobj);
											}else{
												if(iconIndex == -1){
													$("#desk-"+HROS.CONFIG.desk+" li.add-app").before(oldobj);
												}
											}
											HROS.deskTop.appresize();
										}
									});
								}
							}
						}
						if($.browser.msie){
							lay[0].releaseCapture();
						}
					});
					if($.browser.msie){
						lay[0].setCapture();
					}
				}
			});
			//文件夹内图标拖动
			$('.folder_body').off('mousedown','li.app').on('mousedown','li.app',function(e){
				e.preventDefault();
				e.stopPropagation();
				if(e.button == 0 || e.button == 1){
					var oldobj = $(this), x, y, cx, cy, dx, dy, lay, obj = $('<li id="shortcut_shadow">'+oldobj.html()+'</li>');
					dx = cx = e.clientX;
					dy = cy = e.clientY;
					x = dx - oldobj.offset().left;
					y = dy - oldobj.offset().top;
					//绑定鼠标移动事件
					$(document).on("mousemove",function(e){
						$('body').append(obj);
						lay = HROS.maskBox.desk();
						lay.show();
						cx = e.clientX <= 0 ? 0 : e.clientX >= $(document).width() ? $(document).width() : e.clientX;
						cy = e.clientY <= 0 ? 0 : e.clientY >= $(document).height() ? $(document).height() : e.clientY;
						_l = cx - x;
						_t = cy - y;
						if(dx != cx || dy != cy){
							obj.css({left:_l, top:_t}).show();
						}
					});
					//绑定鼠标抬起事件
					$(document).on("mouseup",function(){
						$(document).off("mousemove").off("mouseup");
						obj.remove();
						if(typeof(lay) == 'object'){
							lay.hide();
						}
						//判断是否移动图标，如果没有则判断为click事件
						if(dx == cx && dy == cy){
							HROS.window.create(oldobj.attr('shortcut'));
							return false;
						}
						var folderId = HROS.grid.searchFolderGrid(cx, cy);
						if(folderId != null){
							if(oldobj.parents('.folder-window').attr('window') != folderId){
								$.ajax({
									type: "POST",
									url: ajaxUrl,
									data: "ac=updateMyApp&movetype=folder-folder&id="+oldobj.attr('shortcut')+"&from="+oldobj.parents('.folder-window').attr('window')+"&to="+folderId+"&desk="+HROS.CONFIG.desk,
									success: function(){
										oldobj.remove();
										HROS.deskTop.appresize();
										HROS.window.updateFolder(folderId);
									}
								});
							}
						}else{
							var icon, icon2;
							var iconIndex = $('#desk-'+HROS.CONFIG.desk+' li.shortcut').length == 0 ? -1 : $('#desk-'+HROS.CONFIG.desk+' li').index(oldobj);
							var iconIndex2 = $("#dock-bar .dock-applist").html() == '' ? -1 : $("#dock-bar .dock-applist li").index(oldobj);
							
							var dock_w2 = HROS.CONFIG.dockPos == 'left' ? 0 : HROS.CONFIG.dockPos == 'top' ? ($(window).width()-$("#dock-bar .dock-applist").width()-20)/2 : $(window).width()-$("#dock-bar .dock-applist").width();
							var dock_h2 = HROS.CONFIG.dockPos == 'top' ? 0 : ($(window).height()-$("#dock-bar .dock-applist").height()-20)/2;
							icon2 = HROS.grid.searchDockAppGrid(cx - dock_w2, cy - dock_h2);
							if(icon2 != null){
								$.ajax({
									type: "POST",
									url: ajaxUrl,
									data: "ac=updateMyApp&movetype=folder-dock&id="+oldobj.attr('shortcut')+"&from="+oldobj.parents('.folder-window').attr('window')+"&to="+(icon2+1)+"&desk="+HROS.CONFIG.desk,
									success: function(){
										if(icon2 < iconIndex2){
											$("#dock-bar .dock-applist li.shortcut:eq("+icon2+")").before(oldobj);
										}else if(icon2 > iconIndex2){
											$("#dock-bar .dock-applist li.shortcut:eq("+icon2+")").after(oldobj);
										}else{
											if(iconIndex2 == -1){
												$("#dock-bar .dock-applist").append(oldobj);
											}
										}
										if($("#dock-bar .dock-applist li.shortcut").length > 7){
											$("#desk-"+HROS.CONFIG.desk+" li.shortcut").last().after($("#dock-bar .dock-applist li.shortcut").last());
										}
										HROS.deskTop.appresize();
									}
								});
							}else{
								var dock_w = HROS.CONFIG.dockPos == 'left' ? 73 : 0;
								var dock_h = HROS.CONFIG.dockPos == 'top' ? 73 : 0;
								icon = HROS.grid.searchAppGrid(cx - dock_w, cy - dock_h);
								if(icon != null){
									$.ajax({
										type: "POST",
										url: ajaxUrl,
										data: "ac=updateMyApp&movetype=folder-desk&id="+oldobj.attr('shortcut')+"&from="+oldobj.parents('.folder-window').attr('window')+"&to="+(icon+1)+"&desk="+HROS.CONFIG.desk,
										success: function(){
											if(icon < iconIndex){
												$("#desk-"+HROS.CONFIG.desk+" li.shortcut:eq("+icon+")").before(oldobj);
											}else if(icon > iconIndex){
												$("#desk-"+HROS.CONFIG.desk+" li.shortcut:eq("+icon+")").after(oldobj);
											}else{
												if(iconIndex == -1){
													$("#desk-"+HROS.CONFIG.desk+" li.add-app").before(oldobj);
												}
											}
											HROS.deskTop.appresize();
										}
									});
								}
							}
						}
						if($.browser.msie){
							lay[0].releaseCapture();
						}
					});
					if($.browser.msie){
						lay[0].setCapture();
					}
				}
			});
		},
		/*
		**  加载滚动条
		*/
		getScrollbar: function(){
			setTimeout(function(){
				$('#desk ul').each(function(){
					var desk = $(this), scrollbar = desk.children('.scrollbar');
					//先清空所有附加样式
					scrollbar.hide();
					desk.scrollLeft(0).scrollTop(0);
					/*
					**  判断图标排列方式
					**  横向排列超出屏幕则出现纵向滚动条，纵向排列超出屏幕则出现横向滚动条
					*/
					if(HROS.CONFIG.appXY == 'x'){
						/*
						**  获得桌面图标定位好后的实际高度
						**  因为显示的高度是固定的，而实际的高度是根据图标个数会变化
						*/
						var deskH = parseInt(desk.children('.add-app').css('top')) + 108;
						/*
						**  计算滚动条高度
						**  高度公式（图标纵向排列计算滚动条宽度以此类推）：
						**  滚动条实际高度 = 桌面显示高度 / 桌面实际高度 * 滚动条总高度(桌面显示高度)
						**  如果“桌面显示高度 / 桌面实际高度 >= 1”说明图标个数未能超出桌面，则不需要出现滚动条
						*/
						if(desk.height() / deskH < 1){
							desk.children('.scrollbar-y').height(desk.height() / deskH * desk.height()).css('top',0).show();
						}
					}else{
						var deskW = parseInt(desk.children('.add-app').css('left')) + 106;
						if(desk.width() / deskW < 1){
							desk.children('.scrollbar-x').width(desk.width() / deskW * desk.width()).css('left',0).show();
						}
					}
				});
			},500);
		},
		/*
		**  拖动滚动条
		*/
		moveScrollbar: function(){
			$('.scrollbar').on('mousedown',function(e){
				var x, y, cx, cy, deskrealw, deskrealh, movew, moveh;
				var scrollbar = $(this), desk = scrollbar.parent('ul');
				deskrealw = parseInt(desk.children('.add-app').css('left')) + 106;
				deskrealh = parseInt(desk.children('.add-app').css('top')) + 108;
				console.log(deskrealh);
				movew = desk.width() - scrollbar.width();
				moveh = desk.height() - scrollbar.height();
				if(scrollbar.hasClass('scrollbar-x')){
					x = e.clientX - scrollbar.offset().left;
				}else{
					y = e.clientY - scrollbar.offset().top;
				}
				$(document).on('mousemove',function(e){
					if(scrollbar.hasClass('scrollbar-x')){
						if(HROS.CONFIG.dockPos == 'left'){
							cx = e.clientX - x - 73 < 0 ? 0 : e.clientX - x - 73 > movew ? movew : e.clientX - x - 73;
						}else{
							cx = e.clientX - x < 0 ? 0 : e.clientX - x > movew ? movew : e.clientX - x;
						}
						scrollbar.css('left',(cx / desk.width() * deskrealw) + cx);
						desk.scrollLeft(cx / desk.width() * deskrealw);
					}else{
						if(HROS.CONFIG.dockPos == 'top'){
							cy = e.clientY - y - 73 < 0 ? 0 : e.clientY - y - 73 > moveh ? moveh : e.clientY - y - 73;
						}else{
							cy = e.clientY - y < 0 ? 0 : e.clientY - y > moveh ? moveh : e.clientY - y;
						}
						scrollbar.css('top',cy / desk.height() * deskrealh + cy);
						desk.scrollTop(cy / desk.height() * deskrealh);
					}
				}).on('mouseup',function(){
					$(this).off('mousemove').off('mouseup');
				});
			});
		},
		/*
		**  获得应用评分
		*/
		getStar: function(appid){
			$.ajax({
				type: 'POST',
				url: ajaxUrl,
				data: 'ac=getAppStar&appid='+appid,
				success: function(msg){
					$('#star .star-num').text(Math.floor(msg));
					$('#star i').css('width',(msg*20)+'%');
					$('#star ul').data('appid',appid);
				}
			});
		}
	}
})();

/*
**  应用码头
*/
HROS.dock = (function(){
	return {
		getPos: function(fun){
			$.ajax({
				type: 'POST',
				url: ajaxUrl,
				data: 'ac=getDockPos',
				success: function(i){
					HROS.CONFIG.dockPos = i;
					HROS.dock.setPos();
					if(typeof(fun) != 'undefined'){
						fun();
					}
				}
			});
		},
		setPos: function(){
			var ul = $('#desk-'+HROS.CONFIG.desk), allul = $('#desk ul');
			var desk_w = ul.css('width','100%').width(), desk_h = ul.css('height','100%').height();
			//清除dock位置样式
			$('#dock-container').removeClass('dock-top').removeClass('dock-left').removeClass('dock-right');
			$('#dock-bar').removeClass('top-bar').removeClass('left-bar').removeClass('right-bar').hide();
			if(HROS.CONFIG.dockPos == 'top'){
				$('#dock-bar').addClass('top-bar').children('#dock-container').addClass('dock-top');
				allul.css({'width':desk_w+'px','height':(desk_h-143)+'px','left':desk_w+'px','top':'73px'});
				ul.css({'left':0});
			}else if(HROS.CONFIG.dockPos == 'left'){
				$('#dock-bar').addClass('left-bar').children('#dock-container').addClass('dock-left');
				allul.css({'width':(desk_w-73)+'px','height':(desk_h-70)+'px','left':(desk_w+73)+'px','top':0});
				ul.css({'left':'73px'});
			}else if(HROS.CONFIG.dockPos == 'right'){
				$('#dock-bar').addClass('right-bar').children('#dock-container').addClass('dock-right');
				allul.css({'width':(desk_w-73)+'px','height':(desk_h-70)+'px','left':desk_w+'px','top':0});
				ul.css({'left':0});
			}
			$('#dock-bar').show();
			HROS.taskbar.resize();
		},
		updatePos: function(pos,fun){
			$.ajax({
				type: 'POST',
				url: 'index.php',
				data: 'ac=setDockPos&dock='+pos,
				success: function(){
					HROS.CONFIG.dockPos = pos;
					if(typeof(fun) != 'undefined'){
						fun();
					}
				}
			});
		},
		move: function(){
			$('#dock-container').off('mousedown').on('mousedown',function(e){
				if(e.button == 0 || e.button == 1){
					var lay = HROS.maskBox.dock(), location;
					$(document).on('mousemove',function(e){
						lay.show();
						if(e.clientY < lay.height() * 0.2){
							location = 'top';		
						}else if(e.clientX < lay.width() * 0.5){
							location = 'left';
						}else{				
							location = 'right';
						}
						$('.dock_drap_effect').removeClass('hover');
						$('.dock_drap_effect_'+location).addClass('hover');
					}).on('mouseup',function(){
						$(document).off("mousemove").off("mouseup");
						lay.hide();
						if(location != HROS.CONFIG.dockPos && typeof(location) != 'undefined'){
							HROS.dock.updatePos(location,function(){
								//更新码头位置
								HROS.dock.setPos();
								//更新图标位置
								HROS.deskTop.appresize();
								//更新滚动条
								HROS.app.getScrollbar();
							});
						}
					});
				}
			});
		}
	}
})();

/*
**  壁纸
*/
HROS.wallpaper = (function(){
	return {
		/*
		**	获得壁纸
		**	通过ajax到后端获取壁纸信息，同时设置壁纸
		*/
		get: function(){
			$.ajax({
				type: 'POST',
				url: ajaxUrl,
				data: 'ac=getWallpaper',
				success: function(msg){
					var w = msg.split('<{|}>');
					HROS.CONFIG.wallpaper = w[0];
					HROS.CONFIG.wallpaperType = w[1];
					HROS.CONFIG.wallpaperWidth = w[2];
					HROS.CONFIG.wallpaperHeight = w[3];
					HROS.wallpaper.set();
				}
			});
		},
		/*
		**	设置壁纸
		**	平铺和居中可直接用css样式background解决
		**	而填充、适应和拉伸则需要进行模拟
		*/
		set: function(){
			$('#zoomWallpaperGrid').remove();
			$('.bg').css('background-image','none');
			var w = $(window).width(), h = $(window).height();
			switch(HROS.CONFIG.wallpaperType){
				case 'pingpu':
					$('.bg').css({
						backgroundImage:'url('+HROS.CONFIG.wallpaper+')',
						backgroundPosition:'0 0',
						backgroundRepeat:'repeat'
					});
					break;
				case 'juzhong':
					$('.bg').css({
						backgroundImage:'url('+HROS.CONFIG.wallpaper+')',
						backgroundPosition:'50% 50%',
						backgroundRepeat:'no-repeat'
					});
					break;
				case 'tianchong':
					var t = (h - HROS.CONFIG.wallpaperHeight) / 2, l = (w - HROS.CONFIG.wallpaperWidth) / 2;
					$('body').append('<div id="zoomWallpaperGrid" style="position:absolute;z-index:-10;left:0;top:0;overflow:hidden;height:'+h+'px;width:'+w+'px"><img id="zoomWallpaper" style="position:absolute;height:'+HROS.CONFIG.wallpaperHeight+'px;width:'+HROS.CONFIG.wallpaperWidth+'px;top:'+t+'px;left:'+l+'px"><div style="position:absolute;height:'+h+'px;width:'+w+'px;background:#fff;opacity:0;filter:alpha(opacity=0)"></div></div>');
					$('#zoomWallpaper').attr('src',HROS.CONFIG.wallpaper).on('load',function(){
						$(this).show();
					});
					break;
				case 'shiying':
					var imgH, imgW, t, l;
					if(HROS.CONFIG.wallpaperHeight / HROS.CONFIG.wallpaperWidth > h / w){
						imgH = h;
						imgW = HROS.CONFIG.wallpaperWidth * (h / HROS.CONFIG.wallpaperHeight);
						t = 0;
						l = (w - imgW) / 2;
					}else if(HROS.CONFIG.wallpaperHeight / HROS.CONFIG.wallpaperWidth < h / w){
						imgW = w;
						imgH = HROS.CONFIG.wallpaperHeight * (w / HROS.CONFIG.wallpaperWidth);
						l = 0;
						t = (h - imgH) / 2;
					}else{
						imgH = HROS.CONFIG.wallpaperHeight;
						imgW = HROS.CONFIG.wallpaperWidth;
						t = l = 0;
					}
					$('body').append('<div id="zoomWallpaperGrid" style="position:absolute;z-index:-10;left:0;top:0;overflow:hidden;height:'+h+'px;width:'+w+'px"><img id="zoomWallpaper" style="position:absolute;height:'+imgH+'px;width:'+imgW+'px;top:'+t+'px;left:'+l+'px"><div style="position:absolute;height:'+h+'px;width:'+w+'px;background:#fff;opacity:0;filter:alpha(opacity=0)"></div></div>');
					$('#zoomWallpaper').attr('src',HROS.CONFIG.wallpaper).on('load',function(){
						$(this).show();
					});
					break;
				case 'lashen':
					$('body').append('<div id="zoomWallpaperGrid" style="position:absolute;z-index:-10;left:0;top:0;overflow:hidden;height:'+h+'px;width:'+w+'px"><img id="zoomWallpaper" style="position:absolute;height:'+h+'px;width:'+w+'px;top:0;left:0"><div style="position:absolute;height:'+h+'px;width:'+w+'px;background:#fff;opacity:0;filter:alpha(opacity=0)"></div></div>');
					$('#zoomWallpaper').attr('src',HROS.CONFIG.wallpaper).on('load',function(){
						$(this).show();
					});
					break;
			}
		},
		/*
		**	更新壁纸
		**	通过ajax到后端进行更新，同时获得壁纸
		*/
		update: function(wallpapertype, wallpaper){
			$.ajax({
				type: 'POST',
				url: ajaxUrl,
				data: 'ac=setWallpaper&wptype='+wallpapertype+'&wp='+wallpaper,
				success: function(){
					HROS.wallpaper.get();
				}
			});
		},
	}
})();

/*
**  应用窗口
*/
HROS.window = (function(){
	return {
		/*
		**  创建窗口，可创建系统窗口和自定义窗口
		**  系统窗口：HROS.window.create(id);
		**      id为应用id，也就是数据库tb_apps/tb_folders表的tbid
		**      示例：HROS.window.create(12);
		**  自定义窗口：HROS.window.create(0,{title,url,width,height,resize});
		**      因为是自定义窗口，所以id就写0，不能省略
		**      后面参数依次为：标题、地址、宽、高、是否可拉伸
		**      示例：HROS.window.create(0,{title:"百度",url:"http://www.baidu.com",width:800,height:400,resize:false});
		*/
		create: function(id, obj){
			//判断窗口是否已打开
			var iswindowopen = false, windowid;
			if(id === 0){
				windowid = obj.num == "" ? Date.parse(new Date()) : obj.num;
			}else{
				windowid = id;
			}
			$('#task-content-inner a.task-item').each(function(){
				if($(this).attr('window') == windowid){
					iswindowopen = true;
					HROS.window.show2top(windowid);
				}
			});
			//如果没有打开，则进行创建
			if(iswindowopen == false){
				if(id === 0){
					var options = {
						type	: 'app',
						num		: obj.num == "" ? Date.parse(new Date()) : obj.num,
						imgsrc	: "img/ui/default_icon.png",
						title	: obj.title,
						url		: obj.url,
						width	: obj.width,
						height	: obj.height,
						resize	: obj.resize,
						setbar	: false
					};
					nextDo(options);
				}else{
					ZENG.msgbox.show('应用正在加载中，请耐心等待...',6,100000);
					$.getJSON(ajaxUrl+"?ac=getMyAppById&id="+id,function(app){
						if(app != null){
							ZENG.msgbox._hide();
							var options = {
								type	: app['apptype'],
								num		: app['id'],
								title	: app['iconName'],
								imgsrc	: app['iconUrl'],
								url		: app['url'],
								width	: app['width'],
								height	: app['height'],
								resize	: app['resize'],
								setbar	: app['setbar'],
								appid	: app['appid']
							};
							nextDo(options);
						}else{
							ZENG.msgbox.show('数据拉取失败',5,2000);
						}
					});
				}
				function nextDo(options){
					var window_warp = '#window_' + options.num + '_warp';
					var window_inner = '#window_' + options.num + '_inner';
					var window_frame = '#window_' + options.num + '_frame';
					var window_folder = '#window_' + options.num + '_folder';
					$('.window-mask').show();
					$('iframe, .folder_body').hide();
					$('#task-content-inner a.task-item').removeClass('task-item-current');
					$('.window-container').removeClass('window-current');
					//任务栏，窗口等数据
					TEMP.taskTemp = {"num":options.num,"title":options.title,"imgsrc":options.imgsrc};
					var top = ($(window).height() - options.height) / 2 <= 0 ? 0 : ($(window).height() - options.height) / 2;
					var left = ($(window).width() - options.width) / 2 <= 0 ? 0 : ($(window).width() - options.width) / 2;
					if(options.type == 'app'){
						TEMP.windowTemp = {"width":options.width,"height":options.height,"top":top,"left":left,"emptyW":$(window).width()-options.width,"emptyH":$(window).height()-options.height,"zIndex":HROS.CONFIG.createIndexid,"num":options.num,"title":options.title,"url":options.url,"imgsrc":options.imgsrc};
						TEMP.resizeTemp = {"t":"left:0;top:-8px;width:100%;height:10px;z-index:1;cursor:n-resize","r":"right:-8px;top:0;width:10px;height:100%;z-index:1;cursor:e-resize","b":"left:0;bottom:-8px;width:100%;height:10px;z-index:1;cursor:s-resize","l":"left:-8px;top:0;width:10px;height:100%;z-index:1;cursor:w-resize","rt":"right:-8px;top:-8px;width:10px;height:10px;z-index:2;cursor:ne-resize","rb":"right:-8px;bottom:-8px;width:10px;height:10px;z-index:2;cursor:se-resize","lt":"left:-8px;top:-8px;width:10px;height:10px;z-index:2;cursor:nw-resize","lb":"left:-8px;bottom:-8px;width:10px;height:10px;z-index:2;cursor:sw-resize"};
						TEMP.setbarTemp = {"num":options.num};					
						//新增任务栏
						$('#task-content-inner').prepend(String.formatmodel(taskTemp,TEMP.taskTemp));
						$('#task-content-inner .task-item').length * 114;
						$('#task-content-inner').css('width',($('#task-content-inner .task-item').length * 114)+'px');
						HROS.taskbar.resize();
						//新增窗口
						if(options.resize == 1){
							TEMP.windowTemp['resize'] = String.formatmodel(resizeTemp,TEMP.resizeTemp);
							TEMP.windowTemp['titlebar'] = String.formatmodel(titlebarTemp,{});
							if(window.fullScreenApi.supportsFullScreen){
								TEMP.windowTemp['titlebarFullscreen'] = String.formatmodel(titlebarFullscreenTemp,{});
							}else{
								TEMP.windowTemp['titlebarFullscreen'] = '';
							}
						}else{
							TEMP.windowTemp['resize'] = '';
							TEMP.windowTemp['titlebar'] = '';
							TEMP.windowTemp['titlebarFullscreen'] = '';
						}
						if(options.setbar == 1){
							TEMP.windowTemp['setbar'] = String.formatmodel(setbarTemp,TEMP.setbarTemp);
						}else{
							TEMP.windowTemp['setbar'] = '';
						}
						$('#desk').append(String.formatmodel(windowTemp,TEMP.windowTemp));
						$(window_warp).data('info',TEMP.windowTemp);
						HROS.CONFIG.createIndexid += 1;
						//iframe加载完毕后
						$(window_frame).on('load',function(){
							if(options.resize){
								//绑定窗口缩放事件
								HROS.window.resize($(window_warp));
							}
							//隐藏loading
							$(window_inner + ' .window-frame').children('div').eq(1).fadeOut();
						});
						$(window_warp).on('contextmenu',function(){
							return false;
						});
						//绑定窗口上各个按钮事件
						HROS.window.handle($(window_warp));
						//绑定窗口移动
						HROS.window.move($(window_warp));
						//绑定窗口遮罩层点击事件
						$('.window-mask').off('click').on('click',function(){
							HROS.window.show2top($(this).parents('.window-container').attr('window'));
						});
					}else{
						TEMP.folderWindowTemp = {"width":options.width,"height":options.height,"top":top,"left":left,"emptyW":$(window).width()-options.width,"emptyH":$(window).height()-options.height,"zIndex":HROS.CONFIG.createIndexid,"num":options.num,"title":options.title,"imgsrc":options.imgsrc};
						TEMP.resizeTemp = {"t":"left:0;top:-8px;width:100%;height:10px;z-index:1;cursor:n-resize","r":"right:-8px;top:0;width:10px;height:100%;z-index:1;cursor:e-resize","b":"left:0;bottom:-8px;width:100%;height:10px;z-index:1;cursor:s-resize","l":"left:-8px;top:0;width:10px;height:100%;z-index:1;cursor:w-resize","rt":"right:-8px;top:-8px;width:10px;height:10px;z-index:2;cursor:ne-resize","rb":"right:-8px;bottom:-8px;width:10px;height:10px;z-index:2;cursor:se-resize","lt":"left:-8px;top:-8px;width:10px;height:10px;z-index:2;cursor:nw-resize","lb":"left:-8px;bottom:-8px;width:10px;height:10px;z-index:2;cursor:sw-resize"};
						//新增任务栏
						$('#task-content-inner').prepend(String.formatmodel(taskTemp,TEMP.taskTemp));
						$('#task-content-inner .task-item').length * 114;
						$('#task-content-inner').css('width',($('#task-content-inner .task-item').length * 114)+'px');
						HROS.taskbar.resize();
						//新增窗口
						TEMP.folderWindowTemp['resize'] = String.formatmodel(resizeTemp,TEMP.resizeTemp);
						TEMP.folderWindowTemp['titlebar'] = String.formatmodel(titlebarTemp,{});
						TEMP.folderWindowTemp['setbar'] = '';
						$('#desk').append(String.formatmodel(folderWindowTemp,TEMP.folderWindowTemp));
						$(window_warp).data('info',TEMP.folderWindowTemp);
						HROS.CONFIG.createIndexid += 1;
						//iframe加载完毕后
						$.getJSON(ajaxUrl + "?ac=getMyFolderApp&folderid=" + options.num,function(sc){
							if(sc != null){
								for(i = 0; i < sc.length; i++){
									TEMP.appTemp = {"top":0,"left":0,"title":sc[i]['iconName'],"shortcut":sc[i]['id'],"imgsrc":sc[i]['iconUrl']};
									$(window_folder).append(String.formatmodel(appTemp,TEMP.appTemp));
								}
								HROS.app.move();
							}
							appEvent();
						});
						function appEvent(){
							$(window_warp).on('contextmenu',function(){
								return false;
							});
							//绑定文件夹内图标右击事件
							$(window_folder).find('li.shortcut').on('contextmenu',function(e){
								$(".popup-menu").hide();
								var popupmenu = HROS.popupMenu.app($(this));
								var l = ($(document).width()-e.clientX)<popupmenu.width() ? (e.clientX-popupmenu.width()) : e.clientX;
								var t = ($(document).height()-e.clientY)<popupmenu.height() ? (e.clientY-popupmenu.height()) : e.clientY;
								popupmenu.css({left:l+'px',top:t+'px'}).show();
								return false;
							});
							//绑定窗口缩放事件
							HROS.window.resize($(window_warp));
							//隐藏loading
							$(window_inner + ' .window-frame').children('div').eq(1).fadeOut();
							//绑定窗口上各个按钮事件
							HROS.window.handle($(window_warp));
							//绑定窗口移动
							HROS.window.move($(window_warp));
							//绑定窗口遮罩层点击事件
							$('.window-mask').off('click').on('click',function(){
								HROS.window.show2top($(this).parents('.window-container').attr('window'));
							});
						}
					}
				}
			}
		},
		close: function(id){
			$('#window_'+id+'_warp').removeData('info').html('').remove();
			$('#task-content-inner a.task-item[window="'+id+'"]').html('').remove();
			$('#task-content-inner').css('width',($('#task-content-inner .task-item').length * 114)+'px');
			$('#task-bar, #nav-bar').removeClass('min-zIndex');
			HROS.taskbar.resize();
		},
		hide: function(id){
			HROS.window.show2top(id);
			$('#window_'+id+'_warp').css('visibility','hidden');
			$('#task-content-inner a.task-item[window="'+id+'"]').removeClass('task-item-current');
			if($('#window_'+id+'_warp').attr('ismax') == 1){
				$('#task-bar, #nav-bar').removeClass('min-zIndex');
			}
		},
		max: function(id){
			HROS.window.show2top(id);
			$('#window_'+id+'_inner .title-handle .ha-max').hide().next(".ha-revert").show();
			$('#window_'+id+'_warp').attr('ismax',1).animate({width:'100%',height:'100%',top:0,left:0},200);
			$('#task-bar, #nav-bar').addClass('min-zIndex');
		},
		revert: function(id){
			HROS.window.show2top(id);
			$('#window_'+id+'_inner .title-handle .ha-revert').hide().prev('.ha-max').show();
			var obj = $('#window_'+id+'_warp'), windowdata = obj.data('info');
			obj.attr('ismax',0).animate({width:windowdata['width']+'px',height:windowdata['height']+'px',left:windowdata['left']+'px',top:windowdata['top']+'px'},500);
			$('#task-bar, #nav-bar').removeClass('min-zIndex');
		},
		show2top: function(id){
			//改变任务栏样式
			$('#task-content-inner a.task-item').removeClass('task-item-current');
			$('#task-content-inner a.task-item[window="'+id+'"]').addClass('task-item-current');
			if($('#window_'+id+'_warp').attr('ismax') == 1){
				$('#task-bar, #nav-bar').addClass('min-zIndex');
			}
			//改变窗口样式
			$('#desk .window-container').removeClass('window-current');
			$('#window_'+id+'_warp').addClass('window-current').css({'z-index':HROS.CONFIG.createIndexid}).css('visibility','visible');
			//改变窗口遮罩层样式
			$('#desk .window-mask').show();
			$('#window_'+id+'_inner .window-mask').hide();
			//改变iframe显示
			if($('#window_'+id+'_warp').hasClass('folder-window')){
				$('#desk .folder_body').hide();
				$('#window_'+id+'_inner .folder_body').show();
			}else{
				$('#desk iframe').hide();
				$('#window_'+id+'_inner iframe').show();
			}
			HROS.CONFIG.createIndexid += 1;
		},
		updateFolder: function(folderid){
			var obj = $('#window_'+folderid+'_warp');
			HROS.window.show2top(folderid);
			$.getJSON(ajaxUrl + "?ac=getMyFolderApp&folderid=" + folderid,function(sc){
				if(sc != null){
					var temp = '';
					for(i = 0; i < sc.length; i++){
						TEMP.appTemp = {"top":0,"left":0,"title":sc[i]['iconName'],"shortcut":sc[i]['id'],"imgsrc":sc[i]['iconUrl']};
						temp += String.formatmodel(appTemp,TEMP.appTemp);
					}
					obj.find('.folder_body').html('').append(temp).find('li.shortcut').on('contextmenu',function(e){
						$(".popup-menu").hide();
						TEMP.AppRight = GetAppRight($(this));
						var l = ($(document).width()-e.clientX)<TEMP.AppRight.width() ? (e.clientX-TEMP.AppRight.width()) : e.clientX;
						var t = ($(document).height()-e.clientY)<TEMP.AppRight.height() ? (e.clientY-TEMP.AppRight.height()) : e.clientY;
						TEMP.AppRight.css({left:l+'px',top:t+'px'}).show();
						return false;
					});
					HROS.app.move();
				}
			});
		},
		handle: function(obj){
			obj.on('dblclick','.title-bar',function(e){
				//判断当前窗口是否已经是最大化
				if(obj.find('.ha-max').is(':hidden')){
					obj.find('.ha-revert').click();
				}else{
					obj.find('.ha-max').click();
				}
			}).on('click','.ha-hide',function(){
				HROS.window.hide(obj.attr('window'));
			}).on('click','.ha-max',function(){
				HROS.window.max(obj.attr('window'));
				HROS.window.hackIframeHeight4IE6(obj);
			}).on('click','.ha-revert',function(){
				HROS.window.revert(obj.attr('window'));
				HROS.window.hackIframeHeight4IE6(obj);
			}).on('click','.ha-fullscreen',function(){
				window.fullScreenApi.requestFullScreen(document.getElementById(obj.find('iframe').attr('id')));
			}).on('click','.ha-close',function(){
				HROS.window.close(obj.attr('window'));
			}).on('click','.refresh',function(){
				$("#window_"+obj.attr('window')+"_frame").attr("src",$("#window_"+obj.attr('window')+"_frame").attr("src"));
				updateStyle(obj);
			}).on('click','.help',function(){
				var help = art.dialog({title:'帮助',follow:document.getElementById($(this).attr('id')),width:196});
				$.ajax({
					type: 'POST',
					url: ajaxUrl,
					data: 'ac=getAppRemark&appid='+obj.data('info').num,
					success:function(msg){
						help.content(msg);
					}
				});
			}).on('click','.star',function(){
				art.dialog({title:'给“'+obj.data('info').title+'”打分',width:250,id:'star',content:document.getElementById('star')});
				HROS.app.getStar(obj.data('info').num);
			}).on('contextmenu','.window-container',function(){
				$(".popup-menu").hide();
				return false;
			});
			$('#star ul li').off('click').on('click',function(){
				var num = $(this).attr('num');
				var appid = $(this).parent('ul').data('appid');
				if(!isNaN(num) && /^[1-5]$/.test(num)){
					$.ajax({
						type: 'POST',
						url: ajaxUrl,
						data: 'ac=updateAppStar&appid=' + appid + '&starnum=' + num,
						success: function(msg){
							if(msg){
								alert('打分成功');
								HROS.app.getStar(appid);
							}else{
								alert('你已经打过分了');
							}
						}
					});
				}
			});
			var updateStyle = function(obj){
				$('.window-container').removeClass('window-current');
				obj.addClass('window-current').css({'z-index':HROS.CONFIG.createIndexid});
				HROS.CONFIG.createIndexid += 1;
			};
		},
		move: function(obj){
			obj.on("mousedown",".title-bar",function(e){
				if(obj.attr('ismax') == 1){
					return false;
				}
				HROS.window.show2top(obj.attr('window'));
				var windowdata = obj.data('info');
				x = e.clientX - obj.offset().left;
				y = e.clientY - obj.offset().top;
				//增加背景遮罩层
				TEMP.MoveLayOut = HROS.maskBox.desk();
				var lay = ($.browser.msie) ? TEMP.MoveLayOut : $(window);
				//绑定鼠标移动事件
				lay.on("mousemove",function(e){
					TEMP.MoveLayOut.show();
					//强制把右上角还原按钮隐藏，最大化按钮显示
					obj.find(".ha-revert").hide().prev(".ha-max").show();
					_l = e.clientX - x;
					_t = e.clientY - y;
					_w = windowdata['width'];
					_h = windowdata['height'];
					//鼠标贴屏幕左侧20px内 || 右侧20px内
					//e.clientX <= 20 ? (_w = (lay.width()/2), _h = "100%", _l = 0, _t = 0) : e.clientX >= (lay.width()-21) ? (_w = (lay.width()/2), _h = "100%", _l = (lay.width()/2), _t = 0) : null;
					//窗口贴屏幕顶部10px内 || 底部60px内
					_t = _t <= 10 ? 0 : _t >= lay.height()-30 ? lay.height()-30 : _t;
					obj.css({width:_w,height:_h,left:_l,top:_t});
					obj.data('info').left = obj.offset().left;
					obj.data('info').top = obj.offset().top;
				});
				//绑定鼠标抬起事件
				lay.on("mouseup",function(){
					$(this).off("mousemove").off("mouseup");
					TEMP.MoveLayOut.hide();
					if($.browser.msie){
						TEMP.MoveLayOut[0].releaseCapture();
					}
				});
				if($.browser.msie){
					TEMP.MoveLayOut[0].setCapture();
				}
			});
		},
		resize: function(obj){
			for(rs in TEMP.resizeTemp){
				bindResize(rs);
			}
			function bindResize(r){
				obj.find("div[resize='"+r+"']").on("mousedown",function(e){
					//增加背景遮罩层
					TEMP.MoveLayOut = GetLayOutBox();
					var lay = $.browser.msie ? TEMP.MoveLayOut : $(document);	
					x = e.clientX;
					y = e.clientY;
					w = obj.width();
					h = obj.height();
					lay.on("mousemove",function(e){
						TEMP.MoveLayOut.show();
						_x = e.clientX;
						_y = e.clientY;
						//当拖动到屏幕边缘时，自动贴屏
						_x = _x <= 10 ? 0 : _x >= (lay.width()-12) ? (lay.width()-2) : _x;
						_y = _y <= 10 ? 0 : _y >= (lay.height()-12) ? lay.height() : _y;
						switch(r){
							case "t":
								h+y-_y > HROS.CONFIG.windowMinHeight ? obj.css({height:(h+y-_y)+"px",top:_y+"px"}) : obj.css({height:HROS.CONFIG.windowMinHeight+"px"});
							break;
							case "r":
								w-x+_x > HROS.CONFIG.windowMinWidth ? obj.css({width:(w-x+_x)+"px"}) : obj.css({width:HROS.CONFIG.windowMinWidth+"px"});
							break;
							case "b":
								h-y+_y > HROS.CONFIG.windowMinHeight ? obj.css({height:(h-y+_y)+"px"}) : obj.css({height:HROS.CONFIG.windowMinHeight+"px"});
							break;
							case "l":
								w+x-_x > HROS.CONFIG.windowMinWidth ? obj.css({width:(w+x-_x)+"px",left:_x+"px"}) : obj.css({width:HROS.CONFIG.windowMinWidth+"px"});
							break;
							case "rt":
								h+y-_y > HROS.CONFIG.windowMinHeight ? obj.css({height:(h+y-_y)+"px",top:_y+"px"}) : obj.css({height:HROS.CONFIG.windowMinHeight+"px"});
								w-x+_x > HROS.CONFIG.windowMinWidth ? obj.css({width:(w-x+_x)+"px"}) : obj.css({width:HROS.CONFIG.windowMinWidth+"px"});
							break;
							case "rb":
								w-x+_x > HROS.CONFIG.windowMinWidth ? obj.css({width:(w-x+_x)+"px"}) : obj.css({width:HROS.CONFIG.windowMinWidth+"px"});
								h-y+_y > HROS.CONFIG.windowMinHeight ? obj.css({height:(h-y+_y)+"px"}) : obj.css({height:HROS.CONFIG.windowMinHeight+"px"});
							break;
							case "lt":
								w+x-_x > HROS.CONFIG.windowMinWidth ? obj.css({width:(w+x-_x)+"px",left:_x+"px"}) : obj.css({width:HROS.CONFIG.windowMinWidth+"px"});
								h+y-_y > HROS.CONFIG.windowMinHeight ? obj.css({height:(h+y-_y)+"px",top:_y+"px"}) : obj.css({height:HROS.CONFIG.windowMinHeight+"px"});
							break;
							case "lb":
								w+x-_x > HROS.CONFIG.windowMinWidth ? obj.css({width:(w+x-_x)+"px",left:_x+"px"}) : obj.css({width:HROS.CONFIG.windowMinWidth+"px"});
								h-y+_y > HROS.CONFIG.windowMinHeight ? obj.css({height:(h-y+_y)+"px"}) : obj.css({height:HROS.CONFIG.windowMinHeight+"px"});
							break;
						}
						HROS.window.hackIframeHeight4IE6(obj);
					});
					//绑定鼠标抬起事件
					lay.on("mouseup",function(){
						TEMP.MoveLayOut.hide();
						obj.data('info').width = obj.width();
						obj.data('info').height = obj.height();
						obj.data('info').left = obj.offset().left;
						obj.data('info').top = obj.offset().top;
						obj.data('info').emptyW = $(window).width()-obj.width();
						obj.data('info').emptyH = $(window).height()-obj.height();
						if($.browser.msie){
							TEMP.MoveLayOut[0].releaseCapture();
						}
						$(this).off("mousemove").off("mouseup");
					});
					if($.browser.msie){
						TEMP.MoveLayOut[0].setCapture();
					}
				});
			}
		},
		/*
		**  更新IE6下iframe的高度
		**  因为IE6下iframe高度无法自适应，所以在每次改变窗口大小时都需要计算出iframe的实际高度
		*/
		hackIframeHeight4IE6: function(obj){
			if($.browser.msie && $.browser.version==="6.0"){
				$(obj).find('.window-frame').css("height",($(obj).find('.window-frame').parent().height()-59)+"px");
			}
		}
	}
})();

/*
**  任务栏
*/
HROS.taskbar = (function(){
	return {
		init: function(){
			$('#task-content-inner').off('click').on('click','a.task-item',function(){
				HROS.taskbar.click($(this));
			}).off('contextmenu').on('contextmenu','a.task-item',function(e){
				$('.popup-menu').hide();
				HROS.taskbar.rightClick($(this),e.clientX,e.clientY);
				return false;
			});
		},
		hideAll: function(){
			$("#task-content-inner a.task-item").removeClass("task-item-current");
			$("#desk-"+HROS.CONFIG.desk).nextAll("div.window-container").css('visibility','hidden');
		},
		click: function(obj){
			HROS.window.show2top(obj.attr('window'));
		},
		rightClick: function(obj, x, y){
			$('.popup-menu').hide();
			var popupmenu = HROS.popupMenu.task(obj);
			l = ($(document).width() - x) < popupmenu.width() ? (x - popupmenu.width()) : x;
			t = y - popupmenu.height();
			popupmenu.css({left:l+'px',top:t+'px'}).show();
			return false;
		},
		pageClick: function(showW, realW){
			var overW = realW - showW;
			if(HROS.CONFIG.dockPos == 'right'){
				$('#task-content-inner').animate({marginLeft:0},200);
			}else{
				$('#task-content-inner').animate({marginRight:0},200);
			}
			$('#task-next a').addClass('disable');
			$('#task-pre a').removeClass('disable');
			$('#task-next-btn').off('click').on('click',function(){
				if($(this).hasClass('disable') == false){
					if(HROS.CONFIG.dockPos == 'right'){
						var marginL = parseInt($('#task-content-inner').css('margin-left')) + 114;
						if(marginL >= 0){
							marginL = 0;
							$('#task-next a').addClass('disable');
						}
						$('#task-pre a').removeClass('disable');
						$('#task-content-inner').animate({marginLeft:marginL+'px'},200);
					}else{
						var marginR = parseInt($('#task-content-inner').css('margin-right')) + 114;
						if(marginR >= 0){
							marginR = 0;
							$('#task-next a').addClass('disable');
						}
						$('#task-pre a').removeClass('disable');
						$('#task-content-inner').animate({marginRight:marginR+'px'},200);
					}
				}
			});
			$('#task-pre-btn').off('click').on('click',function(){
				if($(this).hasClass('disable') == false){
					if(HROS.CONFIG.dockPos == 'right'){
						var marginL = parseInt($('#task-content-inner').css('margin-left')) - 114;
						if(marginL <= overW * -1){
							marginL = overW * -1;
							$('#task-pre a').addClass('disable');
						}
						$('#task-next a').removeClass('disable');
						$('#task-content-inner').animate({marginLeft:marginL+'px'},200);
					}else{
						var marginR = parseInt($('#task-content-inner').css('margin-right')) - 114;
						if(marginR <= overW * -1){
							marginR = overW * -1;
							$('#task-pre a').addClass('disable');
						}
						$('#task-next a').removeClass('disable');
						$('#task-content-inner').animate({marginRight:marginR+'px'},200);
					}
				}
			});
		},
		resize: function(){
			if(HROS.CONFIG.dockPos == 'left'){
				$('#task-bar').css('left','73px').css('right',0);
				$('#task-content-inner').removeClass('fl');
			}else if(HROS.CONFIG.dockPos == 'right'){
				$('#task-bar').css('left',0).css('right','73px');
				$('#task-content-inner').addClass('fl');
			}else{
				$('#task-bar').css('left',0).css('right',0);
				$('#task-content-inner').removeClass('fl');
			}
			var w = $('#task-bar').width(), taskItemW = $('#task-content-inner .task-item').length * 114, showW = w - 112;
			if(taskItemW >= showW){
				$('#task-next, #task-pre').show();
				$('#task-content').css('width',showW+'px');
				HROS.taskbar.pageClick(showW, taskItemW);
			}else{
				$('#task-next, #task-pre').hide();
				$('#task-content').css('width','100%');
				$('#task-content-inner').css('margin-right',0).css('margin-left',0);
			}
		}
	}
})();

/*
**  分页导航
*/
HROS.navbar = (function(){
	return {
		/*
		**  初始化
		*/
		init: function(){
			$('#nav-bar').css({'left':($(document).width()/2-105), 'top':30}).show();
			HROS.navbar.move();
			HROS.navbar.deskSwitch();
		},
		/*
		**  拖动
		*/
		move: function(){
			$('#nav-bar').on('mousedown',function(e){
				//e.stopPropagation();
				if(e.button == 0 || e.button == 1){
					var x, y, cx, cy, lay, obj = $('#nav-bar');
					x = e.clientX - obj.offset().left;
					y = e.clientY - obj.offset().top;
					//绑定鼠标移动事件
					$(document).on("mousemove",function(e){
						lay = HROS.maskBox.desk();
						lay.show();
						cx = e.clientX - x <= 0 ? 0 : e.clientX - x > $(document).width() - 210 ? $(document).width() - 210 : e.clientX - x;
						cy = e.clientY - y <= 10 ? 10 : e.clientY - y > $(document).height() - 50 ? $(document).height() - 50 : e.clientY - y;
						obj.css({left:cx,top:cy});
					});
					//绑定鼠标抬起事件
					$(document).on('mouseup',function(){
						if(typeof(lay) !== 'undefined'){
							lay.hide();
						}
						$(this).off('mousemove').off('mouseup');
					});
				}
			});
		},
		/*
		**  点击切换
		*/
		deskSwitch: function(){
			$('#nav-bar .nav-container').on('mousedown','a.indicator',function(e){
				if(e.button == 0 || e.button == 1){
					var x, y, cx, cy, dx, dy, lay, obj = $('#nav-bar'), thisobj = $(this);
					dx = cx = obj.offset().left;
					dy = cy = obj.offset().top;
					x = e.clientX - dx;
					y = e.clientY - dy;
					//绑定鼠标移动事件
					$(document).on("mousemove",function(e){
						lay = HROS.maskBox.desk();
						lay.show();
						cx = e.clientX - x <= 0 ? 0 : e.clientX - x > $(document).width() - 210 ? $(document).width() - 210 : e.clientX - x;
						cy = e.clientY - y <= 10 ? 10 : e.clientY - y > $(document).height() - 50 ? $(document).height() - 50 : e.clientY - y;
						obj.css({left:cx,top:cy});
					});
					//绑定鼠标抬起事件
					$(document).on('mouseup',function(){
						if(dx == cx && dy == cy){
							if(typeof(thisobj.attr('index')) !== 'undefined'){
								var nav = $('#navContainer'), currindex = HROS.CONFIG.desk, switchindex = thisobj.attr('index'),
								currleft = $('#desk-'+currindex).offset().left, switchleft = $('#desk-'+switchindex).offset().left;
								if(currindex != switchindex){
									if(!$('#desk-'+switchindex).hasClass('animated') && !$('#desk-'+currindex).hasClass('animated')){
										$('#desk-'+currindex).addClass('animated').animate({left:switchleft},500,'easeInOutCirc',function(){
											$(this).removeClass('animated');
										});
										$('#desk-'+switchindex).addClass('animated').animate({left:currleft},500,'easeInOutCirc',function(){
											$(this).removeClass('animated');
											nav.removeClass('nav-current-'+currindex).addClass('nav-current-'+switchindex);
											HROS.CONFIG.desk = switchindex;
										});
									}
								}
							}else{
								alert('功能待开发');
							}
						}
						if(typeof(lay) !== 'undefined'){
							lay.hide();
						}
						$(this).off('mousemove').off('mouseup');
					});
				}
			});
		}
	}
})();

/*
**  透明遮罩层
**  当拖动图标、窗口等一切可拖动的对象时，会加载一个遮罩层
**  避免拖动时触发或选中一些不必要的操作，安全第一
**/
HROS.maskBox = (function(){
	return {
		desk: function(){
			if(!TEMP.maskBoxDesk){
				TEMP.maskBoxDesk = $('<div id="maskbox"></div>');
				$('body').append(TEMP.maskBoxDesk);
			}
			return TEMP.maskBoxDesk;
		},
		dock: function(){
			if(!TEMP.maskBoxDock){
				TEMP.maskBoxDock = $('<div style="z-index:1000000003;display:block;cursor:default;background:none;width:100%;height:100%;position:absolute;top:0;left:0"><div id="docktop" class="dock_drap_effect dock_drap_effect_top"></div><div id="dockleft" class="dock_drap_effect dock_drap_effect_left"></div><div id="dockright" class="dock_drap_effect dock_drap_effect_right"></div><div id="dockmask" class="dock_drap_mask"><div class="dock_drop_region_top"></div><div class="dock_drop_region_left"></div><div class="dock_drop_region_right"></div></div></div>');
				$('body').append(TEMP.maskBoxDock);
			}
			return TEMP.maskBoxDock;
		}
	}
})();

/*
**  右键菜单
*/
HROS.popupMenu = (function(){
	return {
		/*
		**  图标右键
		*/
		app: function(obj){
			if(!TEMP.popupMenuApp){
				TEMP.popupMenuApp = $('<div class="popup-menu app-menu" style="z-index:9990;display:none"><ul><li style="border-bottom:1px solid #F0F0F0"><b class="open"></b><a menu="open" href="javascript:;">打开应用</a></li><li><a menu="move" href="javascript:;">移动应用到<b class="arrow">»</b></a><div class="popup-menu" style="display:none"><ul><li><a menu="moveto" desk="1" href="javascript:;">桌面1</a></li><li><a menu="moveto" desk="2" href="javascript:;">桌面2</a></li><li><a menu="moveto" desk="3" href="javascript:;">桌面3</a></li><li><a menu="moveto" desk="4" href="javascript:;">桌面4</a></li><li><a menu="moveto" desk="5" href="javascript:;">桌面5</a></li></ul></div></li><li><b class="uninstall"></b><a menu="del" href="javascript:;">卸载应用</a></li></ul></div>');
				$('body').append(TEMP.popupMenuApp);
				$('.app-menu').on('contextmenu',function(){
					return false;
				});
			}
			$('.app-menu a[menu="moveto"]').removeClass('disabled').each(function(){
				if($(this).attr('desk') == HROS.CONFIG.desk){
					$(this).addClass('disabled');
				}
			});
			//绑定事件
			$('.app-menu li').off('mouseover').off('mouseout').on('mouseover',function(){
				if($(this).children('a').attr('menu') == 'move'){
					$(this).children('a').addClass('focus');
					if($(document).width() - $('.app-menu').offset().left > 250){
						$(this).children('div').css({left:'122px',top:'-2px'});
					}else{
						$(this).children('div').css({left:'-126px',top:'-2px'});
					}
					$(this).children('div').show();
				}
			}).on('mouseout',function(){
				$(this).children('a').removeClass('focus');
				$(this).children('div').hide();
			});
			$('.app-menu a[menu="moveto"]').off('click').on('click',function(){
				var desk = $(this).attr('desk');
				if(!$(this).hasClass('disabled') && (desk != HROS.CONFIG.desk)){
					$.ajax({
						type: 'POST',
						url: ajaxUrl,
						data: 'ac=moveMyApp&id=' + obj.attr('shortcut') + '&fromdesk=' + HROS.CONFIG.desk + '&todesk=' + desk,
						success: function(){
							$("#desk-"+desk+" li.add-app").before(obj);
							HROS.deskTop.appresize();
							HROS.app.getScrollbar();
						}
					});
				}
				$('.task-menu').hide();
			});
			$('.app-menu a[menu="open"]').off('click').on('click',function(){
				HROS.window.create(obj.attr('shortcut'));
				$('.task-menu').hide();
			});
			$('.app-menu a[menu="del"]').off('click').on('click',function(){
				$.ajax({
					type: 'POST',
					url: ajaxUrl,
					data: 'ac=delMyApp&appid=' + obj.attr('shortcut'),
					success: function(){
						obj.find('img, span').show().animate({
							opacity: 'toggle',
							width: 0,
							height: 0
						},500,function(){
							obj.remove();
							HROS.deskTop.resize(250);
						});
					}
				}); 
				$('.task-menu').hide();
			});
			return TEMP.popupMenuApp;
		},
		/*
		**  文件夹右键
		*/
		folder: function(obj){
			if(!TEMP.popupMenuFolder){
				TEMP.popupMenuFolder = $('<div class="popup-menu folder-menu" style="z-index:9990;display:none"><ul><li style="border-bottom:1px solid #F0F0F0"><b class="open"></b><a menu="open" href="javascript:;">打开</a></li><li><b class="edit"></b><a menu="rename" href="javascript:;">重命名</a></li><li><b class="del"></b><a menu="del" href="javascript:;">删除</a></li></ul></div>');
				$('body').append(TEMP.popupMenuFolder);
				$('.folder-menu').on('contextmenu',function(){
					return false;
				});
			}
			//绑定事件
			$('.folder-menu a[menu="open"]').off('click').on("click",function(){
				HROS.window.create(obj.attr('shortcut'));
				$('.task-menu').hide();
			});
			$('.folder-menu a[menu="del"]').off('click').on("click",function(){
				art.dialog({title:'删除“'+obj.find('span').text()+'”文件夹',id:'delfolder',content:'删除文件夹的同时会删除文件夹内所有应用',icon:'warning',ok:function(){
					$.ajax({
						type: 'POST',
						url: ajaxUrl,
						data: 'ac=delMyApp&appid=' + obj.attr('shortcut') + '&isfolder=1',
						success: function(){
							obj.find('img, span').show().animate({
								opacity: 'toggle',
								width: 0,
								height: 0
							},500,function(){
								obj.remove();
								HROS.deskTop.resize(250);
							});
						}
					}); 
				},cancel:true});
				$('.task-menu').hide();
			});
			$('.folder-menu a[menu="rename"]').off('click').on("click",function(){
				$('#folderName').val(obj.find('span').text());
				$('.fcDropdown_item').each(function(){
					if($(this).children('img').attr('src') == obj.find('img').attr('src')){
						$('.folderSelector img').attr('src',obj.find('img').attr('src')).attr('idx',$(this).children('img').attr('idx'));
					}
				});
				$('.folderNameError').hide();
				art.dialog({title:'重命名“'+obj.find('span').text()+'”文件夹',width:400,id:'addfolder',padding:0,content:document.getElementById('addfolder'),ok:function(){
					if($('#folderName').val() != ''){
						$.ajax({
							url:ajaxUrl,
							type:'POST',
							data:'ac=updateFolder&name='+$('#folderName').val()+'&icon='+$('.folderSelector img').attr('idx')+'&id='+obj.attr('shortcut'),
							success:function(){
								HROS.app.get();
							}
						});
					}else{
						$('.folderNameError').show();
						return false;
					}
				},cancel:true});
				$('.folderSelector').off('click').on('click',function(){
					$('.fcDropdown').show();
				});
				$('.fcDropdown_item').off('click').on('click',function(){
					var src = $(this).children('img').attr('src');
					var idx = $(this).children('img').attr('idx');
					$('.folderSelector img').attr('src',src).attr('idx',idx);
					$('.fcDropdown').hide();
				});
				$('.task-menu').hide();
			});
			return TEMP.popupMenuFolder;
		},
		/*
		**  任务栏右键
		*/
		task: function(obj){
			if(!TEMP.popupMenuTask){
				TEMP.popupMenuTask = $('<div class="popup-menu task-menu" style="z-index:9990;display:none"><ul><li><a menu="max" href="javascript:;">最大化</a></li><li style="border-bottom:1px solid #F0F0F0"><a menu="hide" href="javascript:;">最小化</a></li><li><a menu="close" href="javascript:;">关闭</a></li></ul></div>');
				$('body').append(TEMP.popupMenuTask);
				$('.task-menu').on('contextmenu',function(){
					return false;
				});
			}
			//绑定事件
			$('.task-menu a[menu="max"]').off('click').on("click",function(){
				$('#window_'+obj.attr('window')+'_warp').css('visibility','visible');
				$('#window_'+obj.attr('window')+'_inner .title-handle .ha-max').click();
				$('.task-menu').hide();
			});
			$('.task-menu a[menu="hide"]').off('click').on("click",function(){
				$('#window_'+obj.attr('window')+'_inner .title-handle .ha-hide').click();
				$('.task-menu').hide();
			});
			$('.task-menu a[menu="close"]').off('click').on("click",function(){
				HROS.window.close(obj.attr('window'));
				$('.task-menu').hide();
			});
			return TEMP.popupMenuTask;
		},
		/*
		**  桌面右键
		*/
		desk: function(){
			if(!TEMP.popupMenuDesk){
				TEMP.popupMenuDesk = $('<div class="popup-menu desk-menu" style="z-index:9990;display:none"><ul><li><a menu="hideall" href="javascript:;">显示桌面</a></li><li><a menu="refresh" href="javascript:;">刷新</a></li><li style="border-bottom:1px solid #F0F0F0"><a menu="closeall" href="javascript:;">关闭所有应用</a></li><li style="border-bottom:1px solid #F0F0F0"><b class="folder"></b><a menu="addfolder" href="javascript:;">新建文件夹</a></li><li><b class="themes"></b><a menu="themes" href="javascript:;">主题设置</a></li><li><b class="setting"></b><a menu="setting" href="javascript:;">桌面设置</a></li><li style="border-bottom:1px solid #F0F0F0"><a menu="view" href="javascript:;">图标设置<b class="arrow">»</b></a><div class="popup-menu" style="display:none"><ul><li><b class="hook"></b><a menu="orderby" orderby="x" href="javascript:;">横向排列</a></li><li><b class="hook"></b><a menu="orderby" orderby="y" href="javascript:;">纵向排列</a></li></ul></div></li><li><a menu="logout" href="javascript:;">注销</a></li></ul></div>');
				$('body').append(TEMP.popupMenuDesk);
				$('.desk-menu').on('contextmenu',function(){
					return false;
				});
				//绑定事件
				$('.desk-menu li').off('mouseover').off('mouseout').on('mouseover',function(){
					if($(this).children('a').attr('menu') == 'view'){
						$(this).children('a').addClass('focus');
						if($(document).width() - $('.desk-menu').offset().left > 250){
							$(this).children('div').css({left:'122px',top:'-2px'});
						}else{
							$(this).children('div').css({left:'-126px',top:'-2px'});
						}
						$(this).children('div').show();
					}
				}).on('mouseout',function(){
					$(this).children('a').removeClass('focus');
					$(this).children('div').hide();
				});
				$('.desk-menu a[menu="orderby"]').off('click').on('click',function(){
					var xy = $(this).attr('orderby');
					if(HROS.CONFIG.appXY != xy){
						HROS.app.updateXY(xy,function(){
							HROS.deskTop.appresize();
							HROS.app.getScrollbar();
						});
					}
					$('.task-menu').hide();
				});
				$('.desk-menu a[menu="refresh"]').on("click",function(){
					HROS.app.get();
				});
				$('.desk-menu a[menu="hideall"]').on("click",function(){
					HROS.taskbar.hideAll();
				});
				$('.desk-menu a[menu="closeall"]').on("click",function(){
					$('#desk .window-container').each(function(){
						HROS.window.close($(this).attr('window'));
					});
				});
				$('.desk-menu a[menu="addfolder"]').on("click",function(){
					$('#folderName').val('新建文件夹');
					$('.folderSelector img').attr('src','img/ui/folder_default.png').attr('idx','default');
					$('.folderNameError').hide();
					art.dialog({title:'新建文件夹',width:400,id:'addfolder',padding:0,content:document.getElementById('addfolder'),ok:function(){
						if($('#folderName').val() != ''){
							$.ajax({
								url:ajaxUrl,
								type:'POST',
								data:'ac=addFolder&name='+$('#folderName').val()+'&icon='+$('.folderSelector img').attr('idx'),
								success:function(folderid){
									$.ajax({
										url:ajaxUrl,
										type:'POST',
										data:'ac=addMyApp&appid='+folderid+'&desk='+HROS.CONFIG.desk,
										success:function(){
											HROS.app.get();
										}
									}); 
								}
							});
						}else{
							$('.folderNameError').show();
							return false;
						}
					},cancel:true});
					$('.folderSelector').off('click').on('click',function(){
						$('.fcDropdown').show();
					});
					$('.fcDropdown_item').off('click').on('click',function(){
						var src = $(this).children('img').attr('src');
						var idx = $(this).children('img').attr('idx');
						$('.folderSelector img').attr('src',src).attr('idx',idx);
						$('.fcDropdown').hide();
					});
				});
				$('.desk-menu a[menu="themes"]').on("click",function(){
					HROS.window.create(0,{num:"ztsz",title:"主题设置",url:"themes.aspx",width:580,height:520,resize:false});
				});
				$('.desk-menu a[menu="setting"]').on("click",function(){
					HROS.window.create(0,{num:"zmsz",title:"桌面设置",url:"themes.aspx",width:750,height:450,resize:false});
				});
				$('.desk-menu a[menu="logout"]').on("click",function(){
					HROS.base.logout();
				});
			}
			$('.desk-menu a[menu="orderby"]').each(function(){
				$(this).prev().hide();
				if($(this).attr('orderby') == HROS.CONFIG.appXY){
					$(this).prev().show();
				}
			});
			return TEMP.popupMenuDesk;
		}
	}
})();